<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义指令</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2>当前n值：<span v-text="n"></span></h2>
<!--    <h2>放大十倍后的值：<span v-big-number="n"></span></h2>-->
    <h2>放大十倍后的值：<span v-big="n"></span></h2>
    <button @click="n++">点我n+1</button>
    <input type="text" v-fbind:value="n">
</div>
<div id="root2">
    <input type="text" v-fbind:value="x">
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip =false
    //定义全局指令
   /* Vue.directive("fbind",{
        bind(element,binding){
            element.value=binding.value
        },
        inserted(element,binding){
            element.value=binding.value
        },
        update(element,binding){
            element.value=binding.value
        }
    })*/

    new Vue({
        el:'#root',
        data:{
            name:'尚硅谷',
            n:1
        },
        directives:{
            //big何时会被调用？1、指令与元素成功绑定时 2、指令所在的模板被重新解析时。
            // 'big-number'(element,binding){//函数形式
            //    // console.log('big')
            //     element.innerText = binding.value*10
            // },
            big(element,binding){//函数形式
                console.log('big',this)
                element.innerText = binding.value*10
            },
           fbind:{//对象形式
                //指令与元素成功绑定时
                bind(element,binding){
                    element.value=binding.value
                },
                inserted(element,binding){
                    element.value=binding.value
                },
                update(element,binding){
                    element.value=binding.value
                }
            }
        }
    })
    new Vue({
        el:'#root2',
        data:{
            x:1
        }
    })
</script>
</html>